package cn.tedu.huntingmall.controller;

import cn.tedu.huntingmall.commons.response.JsonResult;
import cn.tedu.huntingmall.pojo.dto.myorder.MyOrderAddNewDTO;
import cn.tedu.huntingmall.pojo.entity.myorder.MyOrder;
import cn.tedu.huntingmall.pojo.vo.myorder.MyOrderAddNewVO;
import cn.tedu.huntingmall.service.IMyOrderService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/myorder")
@Api(tags = "用户订单管理模块")
public class MyOrderController {

    @Autowired
    private IMyOrderService service;

    @GetMapping("/insert")
    @ApiOperation("用户订单添加功能")
    @ApiOperationSupport(order = 10)
    public JsonResult<MyOrderAddNewVO> insert(MyOrderAddNewDTO myOrderAddNewDTO){
        Long id = service.insert(myOrderAddNewDTO);
        return JsonResult.ok(new MyOrderAddNewVO().setId(id));
    }

    @GetMapping("/delete")
    @ApiOperation("用户订单删除功能")
    @ApiOperationSupport(order = 20)
    public JsonResult delete(Long id, String username){
        int delete = service.deleteById(id, username);
        return JsonResult.ok(delete);
    }

    @GetMapping("/select/list")
    @ApiOperation("/用户订单查询功能")
    @ApiOperationSupport(order = 40)
    public JsonResult<List<MyOrder>> selectList(String username){
        List<MyOrder> list = service.selectByUsername(username);
        return JsonResult.ok(list);
    }
}
